package cn.edu.cug.cs.gtl.plugins.device.actions;

import cn.edu.cug.cs.gtl.apis.ui.AbstractApplication;
import cn.edu.cug.cs.gtl.apis.ui.actions.AbstractAction;
import cn.edu.cug.cs.gtl.apis.ui.devicetree.DeviceTree;
import cn.edu.cug.cs.gtl.apis.ui.tree.TreeNodeData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.event.ActionEvent;
import java.util.Locale;
import java.util.ResourceBundle;

public class DeleteStorageClusterAction extends AbstractAction {
    @Override
    public void initialize(AbstractApplication theApp) {
        ResourceBundle resourceBundle= ResourceBundle.getBundle("device-resource", Locale.getDefault());
        name=resourceBundle.getString("popupmenu.device.tree.delete_storage_cluster");
        menuItem.setText(name);

        this.theApp = theApp;
        menuItem.addActionListener(this);
        ((DeviceTree) theApp.getMainFrame().getDevicePanel().getTreeComponent()).getStorageClusterNodePopupMenu().add(menuItem);
        ((DeviceTree) theApp.getMainFrame().getDevicePanel().getTreeComponent()).getStorageChildNodePopupMenu().add(menuItem);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //获取当前选中的集群节点
        TreeNodeData deviceTreeNodeData = (TreeNodeData) theApp.getMainFrame().getDevicePanel().getTreeComponent().getCurrentSelectedNode().getUserObject();
        Object refObject = deviceTreeNodeData.getRefObject();
        if(refObject.equals("HDFS")) System.err.println("hdfs");

        int option = JOptionPane.showConfirmDialog(theApp.getMainFrame(), "确认删除？", "确认", JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            //删除节点

        }

    }
}
